package com.jbm.jbmsupplier.shared;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by 家帮忙 on 2017/4/12.
 */

public class SharedPreferActivity {
    private Context context;
    private boolean IsStar;
    private SharedPreferences sharedpre;
    private SharedPreferences.Editor edits;
    private final String keybool="bool";//判断登录key
    private final String keyLoId="Loginid";//保存登录id
    private final String keysql="Sqldb";//好友列表false联网取true本地区
    private final String NetConn="NetConn";//保存网络连接状态false重新链接，true已连接
    private final String UpOrder="UPORDER";//保存报修是否更新新订单状态  true  可更新  false  不可以更新
    private final String UpUserName="UPUSERNAME";//保存修改用户名

    public SharedPreferActivity(Context context) {
        this.context = context;
        init();
    }

    private void init() {
         sharedpre= context.getSharedPreferences("construction", Activity.MODE_PRIVATE);//这个文件不可以清空，可以更改键值
          edits=  sharedpre.edit();

    }

    public SharedPreferActivity(Context context, boolean isStar) {
        this.context = context;
        IsStar = isStar;
        init();
    }
 public void setName(String name,String pwd){
     if (IsStar){
     edits.putString("keyname",name).commit();
     edits.putString("keypwd",pwd).commit();
     }
 }
  public String getNmaes(){
    String name= sharedpre.getString("keyname","");
    String pwd=  sharedpre.getString("keypwd","");
      return name+","+pwd;
  }

    //登录，判断第几次登录
    public void setBoolearLogin(boolean boo){//赋值此方法赋值为true就代表不进入登录页面 false就代表进登录
        edits.putBoolean(keybool,boo).commit();
    }
    public boolean getBoolearLogin(){return sharedpre.getBoolean(keybool,false);//false就是第一次登录 true登录成功
         }
   //保存登录的id
    public void setLoginid(int id){
        edits.putInt(keyLoId,id).commit();
    }
    public  int getLoginid(){
        return sharedpre.getInt(keyLoId,0);
    }

    //获取好友列表 本地  和 网络
    public void setBoolearSql(boolean boo){//赋值此方法赋值为true就代表不进入登录页面 false就代表进登录
        edits.putBoolean(keysql,boo).commit();
    }
    public boolean getBoolearSql(){
        return sharedpre.getBoolean(keysql,false);//代表网络
    }

     //判断网络连接状态
    public void setBoolearNetConn(boolean boo){//赋值此方法赋值为true就代表不进入登录页面 false就代表进登录
        edits.putBoolean(NetConn,boo).commit();
    }
    public boolean getBoolearNetConn(){
        return sharedpre.getBoolean(NetConn,false);//false就是第一次登录 true登录成功
    }

    public void setExitLogin(){//用户退出时调用
        edits.putBoolean(NetConn,false).commit();
        edits.putBoolean(keybool,false).commit();
        edits.putBoolean(keysql,false).commit();
        edits.putBoolean(UpOrder,false).commit();
//        edits.putString("keyname","").commit();
//        edits.putString("keypwd","").commit();
    }
    public void setExitLogins(){//账号被另一个手机登录调用
         edits.putBoolean(NetConn,false).commit();
        edits.putBoolean(keybool,false).commit();
        edits.putBoolean(keysql,false).commit();
        edits.putBoolean(UpOrder,false).commit();
    }



    //更新订单
    public void setBoolearorder(boolean boo){//false代表单子没有任何操作，true 有操作进行更新
        edits.putBoolean(UpOrder,boo).commit();
    }
    public boolean getBoolearorder() {
        return sharedpre.getBoolean(UpOrder, false);//false不更新 true更新
    }
     //保存用户名
        public void setUserName(String name){
                edits.putString(UpUserName,name).commit();
        }
        public String getUserNmaes(){
            return  sharedpre.getString(UpUserName,"");
        }




}
